package com.whfc.fvs.service.xxl.job;

import com.whfc.XxlJobConfig;
import com.whfc.fvs.dao.FvsDeviceMapper;
import com.whfc.fvs.dto.FvsDeviceDTO;
import com.whfc.fvs.dto.FvsStreamDTO;
import com.whfc.fvs.entity.FvsDevice;
import com.whfc.fvs.enums.VsPlatform;
import com.whfc.fvs.service.factroy.FvsPlatformServiceFactory;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @Description 摄像头定时任务
 * @Author hw
 * @Date 2021-08-31 14:24
 * @Version 1.0
 */
@Component
@ConditionalOnBean(XxlJobConfig.class)
public class FvsDeviceJob {


    @Autowired
    private FvsDeviceMapper fvsDeviceMapper;

    @Autowired
    private FvsPlatformServiceFactory platformServiceFactory;


    @PostConstruct
    public void init() {
        getFvsStream();
    }

    @XxlJob("getFvsStream")
    public void getFvsStream() {
        XxlJobHelper.log("开始执行获取视频地址定时任务");
        List<FvsDevice> list = fvsDeviceMapper.selectAll();
        for (FvsDevice fvsDevice : list) {
            try {
                VsPlatform platform = VsPlatform.parseValue(Integer.valueOf(fvsDevice.getPlatform()));
                FvsDeviceDTO fvsDeviceDTO = new FvsDeviceDTO();
                BeanUtils.copyProperties(fvsDevice, fvsDeviceDTO);
                FvsStreamDTO fvsStreamDTO = platformServiceFactory.getFvsPlatFromService(platform).getStreamUrl(fvsDeviceDTO);
            } catch (Exception e) {
                XxlJobHelper.handleFail("获取直播摄像头失败 error" + e.getMessage());
            }

        }
    }

}
